package com.ruoyi.jiajia.controller;

import com.ruoyi.common.annotation.DataScope;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.system.domain.JiajiaWorkerPhoto;
import com.ruoyi.system.service.IJiajiaWorkerPhotoService;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 社工相册Controller
 * 
 * @author knd
 * @date 2021-10-13
 */
@Controller
@RequestMapping("/jiajia/workerPhoto")
public class JiajiaWorkerPhotoController extends BaseController
{
    private String prefix = "jiajia/workerPhoto";

    @Autowired
    private IJiajiaWorkerPhotoService jiajiaWorkerPhotoService;

    @RequiresPermissions("jiajia:workerPhoto:view")
    @GetMapping()
    public String workerPhoto()
    {
        return prefix + "/workerPhoto";
    }

    /**
     * 查询社工相册列表
     */
    @RequiresPermissions("jiajia:workerPhoto:list")
    @PostMapping("/list")
    @ResponseBody
    @DataScope(deptAlias = "d")
    public TableDataInfo list(JiajiaWorkerPhoto jiajiaWorkerPhoto)
    {
        startPage();


        List<JiajiaWorkerPhoto> list = jiajiaWorkerPhotoService.selectJiajiaWorkerPhotoList(jiajiaWorkerPhoto);
        return getDataTable(list);
    }

    /**
     * 导出社工相册列表
     */
    @RequiresPermissions("jiajia:workerPhoto:export")
    @Log(title = "社工相册", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(JiajiaWorkerPhoto jiajiaWorkerPhoto)
    {
        List<JiajiaWorkerPhoto> list = jiajiaWorkerPhotoService.selectJiajiaWorkerPhotoList(jiajiaWorkerPhoto);
        ExcelUtil<JiajiaWorkerPhoto> util = new ExcelUtil<JiajiaWorkerPhoto>(JiajiaWorkerPhoto.class);
        return util.exportExcel(list, "社工相册数据");
    }

    /**
     * 新增社工相册
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存社工相册
     */
    @RequiresPermissions("jiajia:workerPhoto:add")
    @Log(title = "社工相册", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(JiajiaWorkerPhoto jiajiaWorkerPhoto)
    {
        return toAjax(jiajiaWorkerPhotoService.insertJiajiaWorkerPhoto(jiajiaWorkerPhoto));
    }

    /**
     * 修改社工相册
     */
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") Long id, ModelMap mmap)
    {
        JiajiaWorkerPhoto jiajiaWorkerPhoto = jiajiaWorkerPhotoService.selectJiajiaWorkerPhotoById(id);
        mmap.put("jiajiaWorkerPhoto", jiajiaWorkerPhoto);
        return prefix + "/edit";
    }

    /**
     * 修改保存社工相册
     */
    @RequiresPermissions("jiajia:workerPhoto:edit")
    @Log(title = "社工相册", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(JiajiaWorkerPhoto jiajiaWorkerPhoto)
    {
        return toAjax(jiajiaWorkerPhotoService.updateJiajiaWorkerPhoto(jiajiaWorkerPhoto));
    }

    /**
     * 删除社工相册
     */
    @RequiresPermissions("jiajia:workerPhoto:remove")
    @Log(title = "社工相册", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(jiajiaWorkerPhotoService.deleteJiajiaWorkerPhotoByIds(ids));
    }
}
